<?php
namespace zake\server\http;

use zake\foundation\point\Http;
use zake\foundation\reactor\trigger\Listen;

/**
 * Class HttpListen
 * @package zake\server\http
 */
class HttpListen extends Listen
{


    protected $handFuncMap = [];


    /**
     * 构造器
     *
     * HttpListen constructor.
     * @param $uri
     */
    protected function __construct($uri)
    {
        parent::__construct($uri);
        $this->setConnect(HttpConnect::class);
        $this->setProtocol(Http::singleton());
    }



    /**
     * hand func map
     *
     * @author liu.bin 2020-05-07 10:55
     */
    public function handFunc($path,\Closure $callback)
    {
        $this->handFuncMap[$path] = $callback;
    }



    /**
     * 获取处理
     * @param $key
     * @return \Closure|null
     * @author liu.bin 2020-05-07 11:07
     */
    public function getHandFunc($key,$default="/")
    {
        if(isset($this->handFuncMap[$key])){
            return $this->handFuncMap[$key];
        }
        return $this->handFuncMap[$default]??null;
    }


}
